package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.T3rdstock;
import com.ruoyi.system.service.IT3rdstockService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 第三方库存信息Controller
 * 
 * @author ruoyi
 * @date 2024-05-15
 */
@RestController
@RequestMapping("/supplier/3rdstock")
public class T3rdstockController extends BaseController
{
    @Autowired
    private IT3rdstockService t3rdstockService;

    /**
     * 查询第三方库存信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(T3rdstock t3rdstock)
    {
        startPage();
        List<T3rdstock> list = t3rdstockService.selectT3rdstockList(t3rdstock);
        return getDataTable(list);
    }

    /**
     * 导出第三方库存信息列表
     */
    @Log(title = "第三方库存信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, T3rdstock t3rdstock)
    {
        List<T3rdstock> list = t3rdstockService.selectT3rdstockList(t3rdstock);
        ExcelUtil<T3rdstock> util = new ExcelUtil<T3rdstock>(T3rdstock.class);
        util.exportExcel(response, list, "第三方库存信息数据");
    }

    /**
     * 获取第三方库存信息详细信息
     */
    @GetMapping(value = "/{warehouseId}")
    public AjaxResult getInfo(@PathVariable("warehouseId") String warehouseId)
    {
        return success(t3rdstockService.selectT3rdstockByWarehouseId(warehouseId));
    }

    /**
     * 获取商品库存
     */
    @GetMapping(value = "/selectGoodsStockFromT3rdstock")
    public AjaxResult selectGoodsStockFromT3rdstock(T3rdstock t3rdstock)
    {
        return success(t3rdstockService.selectGoodsStockFromT3rdstock(t3rdstock));
    }

    /**
     * 新增第三方库存信息
     */
    @Log(title = "第三方库存信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody T3rdstock t3rdstock)
    {
        return toAjax(t3rdstockService.insertT3rdstock(t3rdstock));
    }

    /**
     * 修改第三方库存信息
     */
    @Log(title = "第三方库存信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody T3rdstock t3rdstock)
    {
        return toAjax(t3rdstockService.updateT3rdstock(t3rdstock));
    }

    /**
     * 增加第三方库存
     */
    @Log(title = "第三方库存信息", businessType = BusinessType.UPDATE)
    @PutMapping("/addNum")
    public AjaxResult addNum(@RequestBody T3rdstock t3rdstock)
    {
        return toAjax(t3rdstockService.updateT3rdstockByAdd(t3rdstock));
    }

    /**
     * 删除第三方库存信息
     */
    @Log(title = "第三方库存信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{warehouseIds}")
    public AjaxResult remove(@PathVariable String[] warehouseIds)
    {
        return toAjax(t3rdstockService.deleteT3rdstockByWarehouseIds(warehouseIds));
    }
}
